package com.qf.demo;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/**
 * 生成PDF文件
 */
public class JavaToPdf {

    // 生成pdf文件的路径
    private static final String DEST = "target/HelloWorld.pdf";

    public static void main(String[] args) throws FileNotFoundException, DocumentException {
        Document document = new Document();
        // 这里的是相对目录写法
        // user.dir 系统属性存放了当前目录，即D:\00qd-2304\41-project\code\member\pdf-demo
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(DEST));
        document.open();
        document.add(new Paragraph("hello world"));
        document.close();
        writer.close();
    }
}
